package com.tj.template.application.trade.output;

import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.DateUtil;
import com.google.common.collect.Lists;
import com.tj.bo.common.conf.api.ResponseData;
import com.tj.bo.trade.client.response.TradeInfoRO;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @program: binary-option
 * @description
 * @author: binary
 * @create: 2020-06-11 10:16
 **/
public class TradeListResponse implements ResponseData {

    /**
     * 交易列表
     */
    private List<TradeInfoResponse> tradeInfoList;

    private boolean hasNextPage;

    public TradeListResponse(List<TradeInfoRO> tradeInfoROS, boolean hasNextPage) {
        List<TradeInfoResponse> tradeList = Lists.newArrayList();
        if(CollectionUtils.isNotEmpty(tradeInfoROS)){
            for(TradeInfoRO tradeInfoRO : tradeInfoROS){
                TradeInfoResponse response = new TradeInfoResponse();
                BeanUtils.copyProperties(tradeInfoRO, response);
                response.setAmount(tradeInfoRO.getAmount().toString());
                response.setProfitAmount(tradeInfoRO.getProfitAmount() != null ? tradeInfoRO.getProfitAmount().stripTrailingZeros().toPlainString() : "");
                response.setOpeningPrice(tradeInfoRO.getOpeningPrice().stripTrailingZeros().toPlainString());
                response.setOpeningTime(DateUtil.getDateTime(tradeInfoRO.getOpeningTime()));
                response.setClosingPrice(tradeInfoRO.getClosingPrice() != null ? tradeInfoRO.getClosingPrice().stripTrailingZeros().toPlainString() : "");
                response.setClosingTime(DateUtil.getDateTime(tradeInfoRO.getClosingTime()));
                response.setCreateDate(DateUtil.getDate(tradeInfoRO.getOpeningTime(), "dd/MM/yyyy HH:mm:ss"));
                tradeList.add(response);
            }
        }
        this.tradeInfoList = tradeList;
        this.hasNextPage = hasNextPage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public TradeListResponse setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
        return this;
    }

    public List<TradeInfoResponse> getTradeInfoList() {
        return tradeInfoList;
    }

    public TradeListResponse setTradeInfoList(List<TradeInfoResponse> tradeInfoList) {
        this.tradeInfoList = tradeInfoList;
        return this;
    }
}
